/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.ui.menu;

import java.util.StringTokenizer;

import com.rcnss.ui.menu.command.AbstractMenuCommand;

/**
 *
 * @author Guesmi
 */
public class UserMenu extends AbstractMenu{
private static final long serialVersionUID = 1L;
	private String sCommandPackage = "com.rcnss.ui.menu.command.MenuCommand";
	private String[][] menuItem = {
        {"Generale", "Profile", "-", "Logout"},
        {"Reclamation", "Nouvelle Reclamation"
                 , "List Reclamations"},
        {"Aide", "A propos"}
    };


    public UserMenu()
    {

    }

    public void generateMenu()
    {
        AbstractMenuCommand t = null;
        for(int i=0; i<menuItem.length; i++)
        {
            MenuItem actual = this.addItem(menuItem[i][0], null);
            if(menuItem[i].length != 1)
            {
                for(int j=1; j<menuItem[i].length; j++)
                {
                    if(menuItem[i][j].equals("-"))
                        actual.addSeparator();
                    else
                    {
                    	try {
                                t = (AbstractMenuCommand)Class.forName(sCommandPackage+
                                                removeSpaces(menuItem[i][j])).newInstance();
                                t.setWindow(getWindow());
                        } catch (Exception e) {
                                t = null;
                                e.printStackTrace();
                        }
                        actual.addItem(menuItem[i][j],t);
                    }
                }
            }
        }
    }

    public String removeSpaces(String s) {
    	  StringTokenizer st = new StringTokenizer(s," ",false);
    	  String t="";
    	  while (st.hasMoreElements()) t += st.nextElement();
    	  return t;
    }
}
